//
//  GKItemViewController.swift
//  MySwiftObject
//
//  Created by wangws1990 on 2019/9/10.
//  Copyright © 2019 wangws1990. All rights reserved.
//

import UIKit

class GKNovelItemController: BaseViewController {
    var chapter :NSInteger = 0;
    var pageIndex:NSInteger = 0;
    var content:GKNovelContent!;
    lazy var titleLab: UILabel = {
        var label :UILabel = UILabel.init();
        label.textColor = UIColor.init(hex: "999999");
        label.font = UIFont.systemFont(ofSize:12);
        return label
    }()
    lazy var subTitleLab: UILabel = {
        var subTitleLab :UILabel = UILabel.init();
        subTitleLab.textColor = UIColor.init(hex: "999999");
        subTitleLab.font = UIFont.systemFont(ofSize: 12);
        subTitleLab.textAlignment = .right;
        return subTitleLab
    }()
    lazy var readView: GKNovelView = {
        var readView = GKNovelView.init(frame: AppFrame)
        readView.backgroundColor = UIColor.clear;
        return readView
    }()
    lazy var mainView: UIImageView = {
        let mainView : UIImageView = UIImageView.init();
        mainView.image = GKNovelSetManager.defaultSkin();
        return mainView;
    }()
    func setModel(model:GKNovelContent, chapter:NSInteger, pageIndex:NSInteger){
        self.content = model;
        self.pageIndex = pageIndex;
        self.chapter = chapter;
        self.readView.content = model.getContetn(page: pageIndex);
        self.titleLab.text = model.title ?? "";
        self.subTitleLab.text = String(pageIndex+1) + "/" + String(model.pageCount);
        self.mainView.image = GKNovelSetManager.defaultSkin();
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(self.mainView);
        self.mainView.snp_makeConstraints { (make) in
            make.edges.equalToSuperview();
        }
        self.view.addSubview(self.readView);
        self.view.addSubview(self.titleLab);
        self.view.addSubview(self.subTitleLab);
        self.titleLab.snp_makeConstraints { (make) in
            make.top.equalTo(STATUS_BAR_HIGHT - 10);
            make.left.equalTo(20);
        }
        self.subTitleLab.snp_makeConstraints { (make) in
            make.right.equalTo(-20);
            make.centerY.equalTo(self.titleLab);
            make.left.equalTo(self.titleLab.snp_right).offset(-20);
        }
        
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews();
        if self.content == nil {
            self.readView.frame = CGRect.init(x:0, y: SCREEN_HEIGHT/2-30, width: SCREEN_WIDTH, height: 60);
        }else{
            self.readView.frame = AppFrame;
        }
    }
    
}
